﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ProxyHero.Common;

namespace ProxyHero.TabPages
{
    public partial class frmException : Form
    {
        delegate void DelegateVoid();
        HttpUility.HttpHelper httpHelper;

        public frmException(string errorMessage)
        {
            InitializeComponent();
            txtMessage.Text = errorMessage;
            TxtHelper.WriteLog(errorMessage);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (httpHelper.PostGuestBook(this.txtMessage.Text))
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MsgBox.ShowMessage("验证码错误，请重新输入！");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnAbort_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Abort;
            this.Close();
        }

        private void frmException_Load(object sender, EventArgs e)
        {
            httpHelper = new ProxyHero.HttpUility.HttpHelper();
            //DelegateVoid needVerifyCode = new DelegateVoid(NeedVerifyCode);
            //this.BeginInvoke(needVerifyCode);
        }

        private void NeedVerifyCode()
        {
            lock (this.pictureBox1)
            {
                this.pictureBox1.Image = httpHelper.GetVerifyCode();
            }
        }
    }
}
